/*****************************************************************
**                                                             	**
**  Copyright (C) 2007 Amlogic,Inc.                            	**
**  All rights reserved                                        	**
**        Filename : NetmenuSetup.c /Project:AVOS		       **
**        Revision : 1.0                                       	**
**                                                             	**
*****************************************************************/
#include "../menu.h"
#include "NetmenuSetupEvent.h"
#include "NetmenuSetup.h"

extern INT8U CurrentOsdSize;
#ifdef ENABLE_NANDDRV
//char VERSION_MENU_STR[]         = __DATE__;
#else
extern char VERSION_MENU_STR[];
#endif
INT32S WinSetup_net_menuMsgProc(PHWND hwnd, INT32U msg_type, INT32S lpParam)
{
    switch( msg_type){
        case WM_SHOWWINDOW:
            return WinSetupOnShow(hwnd, lpParam) ;
    }
    return 0 ;
}

void SetWinSetup_net_menuPalette(void)
{
    YUVENTRY mask_para[4] = {0,79,4095,4095};
    AWSetAlphaMask(0,4, mask_para);
    YUVENTRY palette_para[16] = {0x8000 | 16392,0x8000 | 21176,0x8000 | 17752,0x8000 | 16392,17592,19496,19832,15016,19992,18104,17673,17817,15864,15721,14460,16344};
    AWSetPalette(0,16, palette_para);
    return ;
}

void SetWinSetup_net_menuPos(HWND* pControl, INT8U CurOsdSize)
{
    switch(CurOsdSize){
		
	case OsdSize576i:
	case OsdSize576p:
	case OsdSize480i:
	case OsdSize480p:
	case OsdSize480iCVBS:
	case OsdSize576iCVBS:
    #ifdef SUPPORT_VGA		
	case OsdSizeVga:
    #endif
            RECT NormalWindowRect = {0,0,720,576};
            pControl->winrect = NormalWindowRect;
            CREATEWINDOWPARAM NormalWindowPara = {1,{{0,0,720,576},    {0,0,0,0},{0,0,0,0},{0,0,0,0}},{PF_PALETTE_256,0,0,0},    SetWinSetup_net_menuPalette};
            AWSendMessage(pControl, WM_WINDOW_RESET_DRAW_AREA, (INT32S)&NormalWindowPara);
            break ;
    }//end of switch
    return;
}

HWND *CreateControlWinSetup_net_menu(HWND* pParent,INT8U CurOsdSize)
{
    HWND* pNewControl;
    switch(CurOsdSize){
		
		
	case OsdSize576i:
	case OsdSize576p:
	case OsdSize480i:
	case OsdSize480p:
	case OsdSize480iCVBS:
	case OsdSize576iCVBS:
    #ifdef SUPPORT_VGA		
	case OsdSizeVga:
    #endif
            CREATEWINDOWPARAM Normalwindow_para = {1,{{0,0,720,576},{0,0,0,0},{0,0,0,0},{0,0,0,0}},{PF_PALETTE_256,0,0,0},SetWinSetup_net_menuPalette};
            //Create Menu Window -- 1
            pNewControl = AWCreateWinControl("TWindow","WinSetup_net_menu",WS_OVERLAPPEDWINDOW,
		                      0,0,720,576,NULL, (INT32S)&Normalwindow_para,WinSetup_net_menuMsgProc) ;
            pNewControl->win_id = 0 ;
            break ;
	}//end of switch
            return pNewControl;
}


void SetWinSetupMenuPos(HWND* pControl, INT8U CurOsdSize)
{
    int iLoop;
    switch(CurOsdSize){
		
       
	case OsdSize576i:
	case OsdSize576p:
	case OsdSize576iCVBS:	
            pControl->winrect.top = pControl->parent->winrect.top + 0;
            pControl->winrect.left = pControl->parent->winrect.left + 0;
            pControl->winrect.width = 720;
            pControl->winrect.height = 576;
            pControl->draw_info_num = 25;
            RECT DrawRect576i[25] = {
				{pControl->winrect.left + 0,pControl->winrect.top + 48,720,480},// 0
				{pControl->winrect.left + 10,pControl->winrect.top + 62,120,78}, // 1
				{pControl->winrect.left + 540,pControl->winrect.top + 118,100,28},// 2 VERSION_MENU_STR  540
				
					
				{pControl->winrect.left + 0,pControl->winrect.top + 528,720,48},// 3				
				{pControl->winrect.left + 0,pControl->winrect.top + 0,720,48},// 4

				{pControl->winrect.left + 110,pControl->winrect.top + 188,452,28},// 5
				{pControl->winrect.left + 110,pControl->winrect.top + 188,452,28},// 6

				{pControl->winrect.left + 600,pControl->winrect.top + 174,20,264},// 7
				{pControl->winrect.left + 600,pControl->winrect.top + 186,20,30},// 8			

				{pControl->winrect.left + 120,pControl->winrect.top + 192,230,28},	//9
				{pControl->winrect.left + 120,pControl->winrect.top + 222,230,28},// 10
				{pControl->winrect.left + 120,pControl->winrect.top + 252,230,28},// 11
				{pControl->winrect.left + 120,pControl->winrect.top + 282,230,28},// 12
				{pControl->winrect.left + 120,pControl->winrect.top + 312,230,28},// 13
				{pControl->winrect.left + 120,pControl->winrect.top + 342,230,28},// 14
				{pControl->winrect.left + 120,pControl->winrect.top + 372,230,28},// 15
				{pControl->winrect.left + 120,pControl->winrect.top + 402,230,28},// 16
				
				{pControl->winrect.left + 366,pControl->winrect.top + 192,200,28}, // 17
				{pControl->winrect.left + 366,pControl->winrect.top + 222,200,28},// 18
				{pControl->winrect.left + 366,pControl->winrect.top + 252,200,28},// 19
				{pControl->winrect.left + 366,pControl->winrect.top + 282,200,28},// 20
				{pControl->winrect.left + 366,pControl->winrect.top + 312,200,28},// 21
				{pControl->winrect.left + 366,pControl->winrect.top + 342,200,28},// 22
				{pControl->winrect.left + 366,pControl->winrect.top + 372,200,28},// 23
				{pControl->winrect.left + 366,pControl->winrect.top + 402,200,28},// 24
            };
            for(iLoop=0; iLoop < 25; iLoop++)
                memcpy(&(pControl->draw_info[iLoop]), &DrawRect576i[iLoop], sizeof(RECT));
            break ;
	
	
	case OsdSize480i:
	case OsdSize480p:
	case OsdSize480iCVBS:
    #ifdef SUPPORT_VGA		
	case OsdSizeVga:
    #endif
            pControl->winrect.top = pControl->parent->winrect.top + 0;
            pControl->winrect.left = pControl->parent->winrect.left + 0;
            pControl->winrect.width = 720;
            pControl->winrect.height = 576;
            pControl->draw_info_num = 25;
            RECT NormalDrawRect[25] = {
				{pControl->winrect.left + 0,pControl->winrect.top + 0,720,480},// 0
				{pControl->winrect.left + 10,pControl->winrect.top + 14,120,78}, // 1
				{pControl->winrect.left + 540,pControl->winrect.top + 70,100,28},// 2 VERSION_MENU_STR  540
					
				{pControl->winrect.left + 0,pControl->winrect.top + 480,720,48},// 3				
				{pControl->winrect.left + 0,pControl->winrect.top + 528,720,48},// 4

				
				{pControl->winrect.left + 110,pControl->winrect.top + 140,452,28},// 5
				{pControl->winrect.left + 110,pControl->winrect.top + 140,452,28},// 6

				{pControl->winrect.left + 600,pControl->winrect.top + 126,20,264},// 7
				{pControl->winrect.left + 600,pControl->winrect.top + 138,20,30},// 8			

				{pControl->winrect.left + 120,pControl->winrect.top + 144,230,28},//9
				{pControl->winrect.left + 120,pControl->winrect.top + 174,230,28},// 10
				{pControl->winrect.left + 120,pControl->winrect.top + 204,230,28},// 11
				{pControl->winrect.left + 120,pControl->winrect.top + 234,230,28},// 12
				{pControl->winrect.left + 120,pControl->winrect.top + 264,230,28},// 13
				{pControl->winrect.left + 120,pControl->winrect.top + 294,230,28},// 14
				{pControl->winrect.left + 120,pControl->winrect.top + 324,230,28},// 15
				{pControl->winrect.left + 120,pControl->winrect.top + 354,230,28},// 16
				
				{pControl->winrect.left + 366,pControl->winrect.top + 144,200,28}, // 17
				{pControl->winrect.left + 366,pControl->winrect.top + 174,200,28},// 18
				{pControl->winrect.left + 366,pControl->winrect.top + 204,200,28},// 19
				{pControl->winrect.left + 366,pControl->winrect.top + 234,200,28},//20
				{pControl->winrect.left + 366,pControl->winrect.top + 264,200,28},// 21
				{pControl->winrect.left + 366,pControl->winrect.top + 294,200,28},// 22
				{pControl->winrect.left + 366,pControl->winrect.top + 324,200,28},// 23
				{pControl->winrect.left + 366,pControl->winrect.top + 354,200,28},// 24
            };
            for(iLoop=0; iLoop < 25; iLoop++)
                memcpy(&(pControl->draw_info[iLoop]), &NormalDrawRect[iLoop], sizeof(RECT));
            break ;
	
    }//end of switch
    return;
}

INT32S WinSetupMenuMsgProc(PHWND hwnd, INT32U msg_type, INT32S lpParam)
{
    switch( msg_type){
        case WM_SHOWWINDOW:
            return WinSetupMenuOnShow(hwnd, lpParam) ;
        case WM_KEYDOWN:
            return WinSetupMenuShowOnKeyPress(hwnd, lpParam) ;
		case WM_PAINT:
			return WinSetupMenuOnPaint(hwnd, lpParam);
				
    }
    return 0 ;
}

HWND *CreateControlWinSetupMenu(HWND *pParent,INT8U CurOsdSize)
{
    //Create Control -- WinPicSlideShow
    HWND *pNewControl;
    switch(CurOsdSize){
		case OsdSize480i:
		case OsdSize480p:
		case OsdSize576i:
		case OsdSize576p:
		case OsdSize480iCVBS:
		case OsdSize576iCVBS:
          #ifdef SUPPORT_VGA		
      		case OsdSizeVga:
          #endif
            pNewControl = AWCreateWinControl("TControl","WinSetupMenu",(WS_CHILDWINDOW | WS_CHILDWINDOW),
		                      0,0,720,576,pParent,0,WinSetupMenuMsgProc) ;
            pNewControl->win_id = 11 ;
            pNewControl->draw_info_num = 25;
            pNewControl->draw_info = (PDRAWINFO)AVMem_umalloc(sizeof(DRAWINFO) * pNewControl->draw_info_num) ;
            DRAWINFO NormalDrawDatas[25] = {
				          
			{0,0,0,0,(INT32U)0,DT_RLE_BMP_DATA},//0
			{0,0,0,0,(INT32U)ICON_SETUP_TOP,DT_RLE_BMP_DATA},// 1                          
			{0,0,0,0,(INT32U)VERSION_MENU_STR,DT_STRING_DATA},// 2

			{0,0,0,0,(INT32U)0,DT_RLE_BMP_DATA},// 3 top
			{0,0,0,0,(INT32U)0,DT_RLE_BMP_DATA},// 4 bottom

			
			{0,0,0,0,(INT32U)ICON_SETUP_BAR,DT_RLE_BMP_DATA},// 5
			{0,0,0,0,(INT32U)ICON_SETUP_SELECT_BAR,DT_RLE_BMP_DATA},// 6

			{0,0,0,0,(INT32U)ICON_PROCESS_BAR,DT_RLE_BMP_DATA},// 7
			{0,0,0,0,(INT32U)ICON_SLIDE_BAR,DT_RLE_BMP_DATA},//8

			{0,0,0,0,(INT32U)MENU_LANGUAGE,DT_RESOURCE_STRING_DATA},//9
			{0,0,0,0,(INT32U)SLIDESHOW_DUR_STR,DT_RESOURCE_STRING_DATA},// 10
			{0,0,0,0,(INT32U)SLIDESHOW_MODE_STR,DT_RESOURCE_STRING_DATA},//11
			{0,0,0,0,(INT32U)MUSIC_REPEAT_STR,DT_RESOURCE_STRING_DATA},// 12
			{0,0,0,0,(INT32U)MOVIE_REPEAT_STR,DT_RESOURCE_STRING_DATA},// 13
			{0,0,0,0,(INT32U)DISPLAY_MODE_STR,DT_RESOURCE_STRING_DATA},// 14
			{0,0,0,0,(INT32U)TV_SYSTEM_STR,DT_RESOURCE_STRING_DATA},// 15
			{0,0,0,0,(INT32U)AUTO_RUN_STR,DT_RESOURCE_STRING_DATA},// 16    

			{0,0,0,0,(INT32U)LANGUAGE_CHINESE_STR,DT_RESOURCE_STRING_DATA},// 17
			{0,0,0,0,(INT32U)SLIDE_TIME_5S_STR,DT_RESOURCE_STRING_DATA},// 18
			{0,0,0,0,(INT32U)SLIDESHOW_MODE_10_STR,DT_RESOURCE_STRING_DATA},// 19
			{0,0,0,0,(INT32U)REPEAT_ALL_STR,DT_RESOURCE_STRING_DATA},// 20
			{0,0,0,0,(INT32U)REPEAT_ALL_STR,DT_RESOURCE_STRING_DATA},// 21
			{0,0,0,0,(INT32U)DISPLAY_MODE_43_STR,DT_RESOURCE_STRING_DATA},// 22
#ifdef WISTAR_VERSION
			{0,0,0,0,(INT32U)TV_SYSTEM_480P_STR,DT_RESOURCE_STRING_DATA},//23
#else
			{0,0,0,0,(INT32U)TV_SYSTEM_480I_STR,DT_RESOURCE_STRING_DATA},//23
#endif			
			{0,0,0,0,(INT32U)AUTO_RUN_OPEN_STR,DT_RESOURCE_STRING_DATA},//24
			
						  
						  };
            memcpy(pNewControl->draw_info,NormalDrawDatas, sizeof(DRAWINFO) * pNewControl->draw_info_num) ;

			DisplayMenuOptionFromEEPROM(pNewControl);
				
			break ;
			
	}//end of switch
            return pNewControl;
}

HWND *CreateWinSetupMenu(void)
{
    HWND *pNewControl ;
    TWINDOWS *pWin;
    HWND *pWinSetup_net_menu = CreateControlWinSetup_net_menu(NULL,CurrentOsdSize);
    SetWinSetup_net_menuPos(pWinSetup_net_menu,CurrentOsdSize);

   

    pNewControl= CreateControlWinSetupMenu(pWinSetup_net_menu,CurrentOsdSize);
    SetWinSetupMenuPos(pNewControl,CurrentOsdSize);


    pWin = (TWINDOWS *)pWinSetup_net_menu;
    pWin->pFocusControl = AWFindWinCtrlByName("WinSetupMenu");//WinPicSlideShow,WinSetup_net_menu
    return pWinSetup_net_menu;
}
/*

void WinResetWinSetup_net_menuControlsPos(HWND *pControl, INT8U CurOsdSize)
{
    switch(pControl->win_id){
        case 0://WinSetup_net_menu
            SetWinSetup_net_menuPos(pControl,CurOsdSize) ;
            break ;
        case 1://WinSetup_net_menuGUI
            SetWinSetup_net_menuGUIPos(pControl,CurOsdSize) ;
            break ;
        case 4://WinSetup_net_menuGUILanguage
            SetWinSetup_net_menuGUILanguagePos(pControl,CurOsdSize) ;
            break ;
        case 9://WinSetup_net_menuVersion
            SetWinSetup_net_menuVersionPos(pControl,CurOsdSize) ;
            break ;
        case 10://WinPicturePlayMode
            SetWinPicturePlayModePos(pControl,CurOsdSize) ;
            break ;
        case 11://WinPicSlideShow
            SetWinSetupMenuPos(pControl,CurOsdSize) ;
            break ;
        case 12://WinMulti_display_screen
            SetWinMulti_display_screenPos(pControl,CurOsdSize) ;
            break ;
	#ifdef ENABLE_CHANGE_OUTPUT
        case 13://WinchangeOutputMode
            SetWinchangeOutputModePos(pControl,CurOsdSize) ;
            break ;
    #endif
    }//end of switch
}
void WinResetWinSetup_net_menuPos(HWND *pControl, INT8U CurOsdSize)
{
    HWND *pChildControl;
    if(pControl == NULL)
        pControl = AWFindWinCtrlByName("WinSetup_net_menu");
    if(pControl == NULL) return ;

    WinResetWinSetup_net_menuControlsPos(pControl, CurOsdSize) ;
    pChildControl = pControl->children ;
    while(pChildControl != NULL){
    	WinResetWinSetup_net_menuPos(pChildControl, CurOsdSize) ;
    	pChildControl = pChildControl->siblings ;
	}
	return ;
}
*/
